import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:url_launcher/url_launcher.dart';

class CrisisInterventionScreen extends StatelessWidget {
  const CrisisInterventionScreen({Key? key}) : super(key: key);

  Future<void> _makePhoneCall(String phoneNumber) async {
    final Uri launchUri = Uri(
      scheme: 'tel',
      path: phoneNumber,
    );
    if (await canLaunchUrl(launchUri)) {
      await launchUrl(launchUri);
    }
  }

  Widget _buildEmergencyAlert() {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16),
      padding: const EdgeInsets.all(16),
      decoration: BoxDecoration(
        color: const Color(0xFFFFEBEE),
        borderRadius: BorderRadius.circular(12),
      ),
      child: Row(
        children: [
          const Icon(
            Icons.warning_amber_rounded,
            color: Colors.red,
            size: 24,
          ),
          const SizedBox(width: 12),
          Expanded(
            child: Text(
              '如果你正处于危机状态，请立即寻求帮助',
              style: GoogleFonts.zcoolKuaiLe(
                fontSize: 16,
                color: Colors.red,
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _buildContactCard({
    required String title,
    required String phoneNumber,
    required IconData icon,
    bool isHotline = false,
  }) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        border: Border.all(
          color: isHotline ? Colors.red.withOpacity(0.6) : Colors.grey.shade200,
          width: isHotline ? 1.5 : 1,
        ),
      ),
      child: ListTile(
        leading: Icon(icon, color: Colors.red),
        title: Text(
          title,
          style: GoogleFonts.zcoolKuaiLe(
            fontSize: 16,
            color: Colors.black87,
          ),
        ),
        trailing: isHotline
          ? Text(
              phoneNumber,
              style: GoogleFonts.zcoolKuaiLe(
                fontSize: 16,
                color: Colors.red,
                fontWeight: FontWeight.bold,
              ),
            )
          : TextButton(
              onPressed: () {},
              child: Text(
                '添加',
                style: GoogleFonts.zcoolKuaiLe(
                  fontSize: 14,
                  color: Colors.blue,
                ),
              ),
            ),
      ),
    );
  }

  Widget _buildGuideCard({
    required String title,
    required String description,
    required IconData icon,
  }) {
    return Container(
      margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
        border: Border.all(color: Colors.grey.shade200),
      ),
      child: ListTile(
        title: Text(
          title,
          style: GoogleFonts.zcoolKuaiLe(
            fontSize: 16,
            color: Colors.black87,
          ),
        ),
        subtitle: Text(
          description,
          style: GoogleFonts.zcoolKuaiLe(
            fontSize: 14,
            color: Colors.grey[600],
          ),
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[50],
      appBar: AppBar(
        backgroundColor: Colors.white,
        elevation: 0,
        leading: IconButton(
          icon: const Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () => Navigator.of(context).pop(),
        ),
        title: Text(
          '危机干预',
          style: GoogleFonts.zcoolKuaiLe(
            fontSize: 20,
            fontWeight: FontWeight.bold,
          ),
        ),
        centerTitle: true,
      ),
      body: ListView(
        children: [
          const SizedBox(height: 16),
          _buildEmergencyAlert(),
          const SizedBox(height: 24),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Text(
              '紧急联系人',
              style: GoogleFonts.zcoolKuaiLe(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Colors.black87,
              ),
            ),
          ),
          const SizedBox(height: 8),
          _buildContactCard(
            title: '心理咨询热线',
            phoneNumber: '12320',
            icon: Icons.phone,
            isHotline: true,
          ),
          _buildContactCard(
            title: '紧急联系人',
            phoneNumber: '',
            icon: Icons.person_add_outlined,
          ),
          const SizedBox(height: 24),
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16),
            child: Text(
              '危机处理指南',
              style: GoogleFonts.zcoolKuaiLe(
                fontSize: 18,
                fontWeight: FontWeight.bold,
                color: Colors.black87,
              ),
            ),
          ),
          const SizedBox(height: 8),
          _buildGuideCard(
            title: '深呼吸练习',
            description: '慢慢吸气5秒，屏住2秒，慢慢呼气5秒',
            icon: Icons.air,
          ),
          _buildGuideCard(
            title: '5-4-3-2-1法则',
            description: '找出你能看到的5样东西，听到的4种声音...',
            icon: Icons.format_list_numbered,
          ),
          _buildGuideCard(
            title: '安全计划',
            description: '制定个人危机应对计划，预防危机发生',
            icon: Icons.security,
          ),
          const SizedBox(height: 24),
        ],
      ),
    );
  }
} 